﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Data.SqlClient;

namespace 游戏平台原型
{
    public partial class regwindow : UserControl
    {
        private NOPHandler m_showlogin;//声明委托变量
        public regwindow(NOPHandler showlogin)
        {
            InitializeComponent();
            this.m_showlogin = showlogin;
        }

        private void btn_reg_reg_Click(object sender, EventArgs e)
        {
            if (tb_reg_password.Text != tb_reg_confirmpassword.Text)
            {
                MessageBox.Show("两次密码输入不一致！");
                return;
            }
            if (tb_reg_username.Text == String.Empty || tb_reg_password.Text == String.Empty || tb_reg_email.Text == String.Empty || tb_reg_confirmpassword.Text == String.Empty)
                return;

            Connection conn = new Connection();
            conn.sql("select username from userinfo where username='" + tb_reg_username.Text + "'");
            if (conn.dr.HasRows)
            {
                MessageBox.Show("用户名已存在！");
                conn.dr.Close();
                return;
            }
            conn.sql("INSERT INTO userinfo (username, password, email) VALUES (N'" + tb_reg_username.Text + "', N'" + tb_reg_password.Text + "', N'" + tb_reg_email.Text + "')");
            conn.dr.Close();
            MessageBox.Show("注册成功！");
            if (this.m_showlogin != null)
            {
                this.m_showlogin();
            }
        }

        private void btn_reg_return_Click(object sender, EventArgs e)
        {
            if (this.m_showlogin != null)
            {
                this.m_showlogin();
            }
        }
    }
}
